//
//  LevelSelectTableViewController.m
//  Checkers2015
//
//  Created by Dmitry Tatarinov on 2/16/15.
//  Copyright (c) 2015 Huly-Gun Soft. All rights reserved.
//

#import "LevelSelectTableViewController.h"

@interface LevelSelectTableViewController ()
{
    UITableView *table;
    NSMutableArray *array;
}

@end

@implementation LevelSelectTableViewController
@synthesize delegate;

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setTitle:@"Back" forState:UIControlStateNormal];
    [backBtn setFrame:CGRectMake(8, 8, 128, 48)];
    [backBtn addTarget:self action:@selector(backToMain) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
    
    
    CGFloat ofset = 20.0;
    
    table = [[UITableView alloc] initWithFrame:CGRectMake(ofset, ofset * 3, self.view.frame.size.width - ofset * 2, self.view.frame.size.height - ofset * 4) style:UITableViewStylePlain];
    table.delegate = self;
    table.dataSource = self;
    [self.view addSubview:table];
    
    array = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)backToMain
{
    [delegate loadMainView];
    [self dismissViewControllerAnimated:false completion:nil];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [array count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:CellIdentifier];
    }
    
    cell.textLabel.text = [array objectAtIndex:indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    gameProhod = (int)(indexPath.row + 1);
    blackStartLine = 0;
    whiteStartLine = 0;
    [delegate startGame];
    [self dismissViewControllerAnimated:false completion:nil];
}

@end
